<template>
  <BaseLayout>
    <template v-slot:main-left>
      <Institution />
    </template>
    <template v-slot:main-button>
      <mainButton
        @toMainSearch="search"
        @toMainSearchReset="reset"
        :main-button="mainButton"
      />
    </template>
    <template v-slot:search-info>
      <searchMain
        size="mini"
        :label-width="labelWidth"
        ref="searchMain"
        :model="formData"
        :rules="searchRules"
        :itemList="formItemList"
      />
      <el-divider />
    </template>
    <template v-slot:table-main>
      <common-table
        :data="infoList"
        border
        :columns-item="columns"
        :title="infoTitle"
        :loading="false"
        @checkbox-change="selectChangeEvent"
      />
    </template>
    <template v-slot:table-member>
      <common-table
        :data="testList"
        border
        :columns-item="testColumns"
        :title="testTitle"
        @checkbox-change="selectChangeEvent"
      />
    </template>
  </BaseLayout>
</template>

<script>
import BaseLayout from "@/components/Layout/base.vue"
import Institution from "@/components/Trees/Institution.vue"
import mainButton from "@/components/CommonButtons/MainButton.vue"
import searchMain from "@/components/CommonForm/index.vue"
import CommonTable from "@/components/CommonTable/index.vue"
// 加载模拟数据
import { checkType, sexs } from "@/simdata/healthData.js"
export default {
  components: {
    BaseLayout,
    Institution,
    mainButton,
    searchMain,
    CommonTable
  },
  data() {
    return {
      // 配置常用按钮
      mainButton: [
        {
          label: "新增",
          icon: "el-icon-circle-plus-outline",
          type: "primary",
          handle: () => this.addHandle()
        },
        {
          label: "修改",
          icon: "el-icon-edit",
          type: "success",
          handle: () => {
            console.log("点击了")
          }
        },
        {
          label: "删除",
          icon: "el-icon-delete",
          type: "danger",
          handle: () => {
            console.log("点击了")
          }
        }
      ],
      // 查询表单
      formData: {
        keyword: "",
        keyValue: "",
        createDate: null, // 建档日期 开始
        endDate: null, // 结束日期
        check: 3,
        startAge: "",
        endAge: ""
      },
      // label的宽度
      labelWidth: "auto",
      searchRules: {},
      // 配置search label表单
      formItemList: [
        {
          type: "myInformation",
          label: "个人信息查询项目",
          span: 16,
          options: [
            { label: "健康档案号", value: 1 },
            { label: "家庭档案号", value: 2 },
            { label: "姓名", value: 3 },
            { label: "身份证号", value: 4 }
          ]
        },
        {
          type: "Select",
          label: "是否体检",
          prop: "check",
          span: 8,
          options: checkType,
          placeholder: "请选择..."
        },
        {
          type: "Input",
          label: "年龄段",
          prop: "startAge",
          span: 6,
          placeholder: ""
        },
        {
          type: "Input",
          label: "至",
          prop: "endAge",
          span: 3,
          placeholder: ""
        },
        {
          type: "data",
          label: "建档日期",
          prop: "createDate",
          span: 7,
          placeholder: "请选择..."
        },
        {
          type: "data",
          label: "至",
          prop: "endDate",
          span: 5,
          placeholder: "请选择..."
        }
      ],
      // 所有列表数据
      infoTitle: "人员基本信息列表",
      testTitle: "儿童体检信息列表",
      infoList: [],
      testList: [],
      // 配置显示的label标签
      columns: [
        { prop: "name", label: "姓名", width: "100" },
        {
          prop: "sex",
          label: "性别",
          width: "68",
          type: "sex",
          option: sexs
        },
        { prop: "age", label: "年龄", width: "100" },
        { prop: "birthdata", label: "出生日期", width: "100" },
        { prop: "identityNumber", label: "身份证号", width: "180" },
        { prop: "phonenumber", label: "电话号码", width: "150" },
        { prop: "nowAddress", label: "居住地址", width: "150" },
        { prop: "number", label: "家庭档案号", width: "150" },
        { prop: "myNumber", label: "个人健康档案号", width: "150" },
        { prop: "checkNum", label: "体检次数", width: "100" }
      ],
      // test配置label标签
      testColumns: [
        { prop: "age", label: "月龄", width: "150" },
        { prop: "organ", label: "体检机构", width: "150" },
        { prop: "createDate", label: "体检日期", width: "100" },
        { prop: "checkModel", label: "体检类型", width: "150" }
      ]
    }
  },
  methods: {
    // 点击新增按钮
    addHandle() {
      console.log("点击新增了")
    },
    // 切换常用地址
    handleChange() {
      console.log("点击了")
    },
    // 点击搜索按钮
    search(formName) {
      this.$refs.searchMain.$refs[formName].validate(valid => {
        if (valid) {
          console.log(this.formData)

          // 调用接口
          this.callbackComponent()
        } else {
          console.log("error submit!!")
          return false
        }
      })
    },
    // 点击重置按钮
    reset(formName) {
      this.$refs.searchMain.$refs[formName].resetFields()
      // console.log(this.formData)
    },
    // 点击搜索后，请求后台接口了
    callbackComponent() {
      console.log("调接口")
    },
    // 家庭基本信息复选框选中
    selectChangeEvent({ checked, records }) {
      console.log(checked)
      console.log(records)
    }
  }
}
</script>
<style lang="scss" scoped></style>
